using System;
using Microsoft.SPOT;
using System.Text;

namespace YeelightBlueDemo
{
    internal static class StringUtilities
    {
        public static string PadHelper(string original, int totalWidth, char paddingChar, bool appendLeft)
        {
            // this seems to be quicker than a simple while (length < totalWidth) pad
            if (original.Length >= totalWidth)
                return original;
            StringBuilder result = new StringBuilder(totalWidth);
            int padCount = totalWidth - original.Length;
            for (int i = 0; i < padCount; i++)
                result.Append(paddingChar);
            if (appendLeft)
                return result + original;
            return original + result;
        }

        public static string PadLeft(this string original, int totalWidth, char paddingChar = ' ')
        {
            return PadHelper(original, totalWidth, paddingChar, true);
        }

        public static string PadRight(this string original, int totalWidth, char paddingChar = ' ')
        {
            return PadHelper(original, totalWidth, paddingChar, false);
        }
    }
}
